package _mst;

/**
 * 面试题 03.01. 三合一
 */
public class T0301 {
    private int[] stack;
    private int stackSize;
    private int[] stackIndex;

    public T0301(int stackSize) {
        stack = new int[stackSize * 3];
        this.stackSize = stackSize;
        stackIndex = new int[3];
    }

    public void push(int stackNum, int value) {
        if (stackIndex[stackNum] == stackSize) return;
        stack[stackNum * stackSize + stackIndex[stackNum]++] = value;
    }

    public int pop(int stackNum) {
        if (stackIndex[stackNum] == 0) return -1;
        return stack[stackNum * stackSize + --stackIndex[stackNum]];
    }

    public int peek(int stackNum) {
        if (stackIndex[stackNum] == 0) return -1;
        return stack[stackNum * stackSize + stackIndex[stackNum] - 1];
    }

    public boolean isEmpty(int stackNum) {
        return stackIndex[stackNum] == 0;
    }
}
